<?php
/**
 * Created by PhpStorm.
 * User: Lee
 * Date: 2020/1/3
 * Time: 9:51
 */
namespace App\Services\Backend\System;

use App\Common\Exception\ErrorException;

/**
 * 系统管理-角色管理 (服务)
 */
class OperationService
{
    /** @var \App\Repositories\Backend\System\OperationRepository $operationRepository */
    private $operationRepository;

    public function __construct()
    {
        $this->operationRepository = app('operationRepository');
    }

    public function getVisibleAffairEventOperation($role_id){
//        if ($role_id == STUDENT_ROLEID){
//            $sql = "SELECT o.actionid,o.actionname,e.eventtypeid,e.eventtypename,e.path epath,e.iconcls eiconcls,a.affairtypeid,a.affairtypename,a.path apath,a.iconcls aiconcls,a.isleaf aleaf FROM operations o,eventtypes e,affairtypes a WHERE o.eventtypeid=e.eventtypeid AND e.affairtypeid=a.affairtypeid AND a.isvisible='1' AND e.isvisible='1' AND o.isvisible='1' AND e.eventtypeid IN ('100300','100400','200400','200500','200600','400100') ORDER BY a.sortnum ASC,a.affairtypeid ASC,e.sortnum ASC,e.eventtypeid,o.sortnum ASC,o.actionid ASC,o.actionid ASC";
//        }else{
//            $sql = "SELECT o.actionid,o.actionname,e.eventtypeid,e.eventtypename,e.path epath,e.iconcls eiconcls,a.affairtypeid,a.affairtypename,a.path apath,a.iconcls aiconcls,a.isleaf aleaf FROM operations o,eventtypes e,affairtypes a WHERE o.eventtypeid=e.eventtypeid AND e.affairtypeid=a.affairtypeid AND a.isvisible='1' AND e.isvisible='1' AND o.isvisible='1' AND e.eventtypeid NOT IN ('100300','100400','200400','200500','200600','400100') ORDER BY a.sortnum ASC,a.affairtypeid ASC,e.sortnum ASC,e.eventtypeid,o.sortnum ASC,o.actionid ASC,o.actionid ASC";
//        }
        $sql = "SELECT o.actionid,o.actionname,e.eventtypeid,e.eventtypename,e.path epath,e.iconcls eiconcls,a.affairtypeid,a.affairtypename,a.path apath,a.iconcls aiconcls,a.type aleaf FROM operations o,eventtypes e,affairtypes a WHERE o.eventtypeid=e.eventtypeid AND e.affairtypeid=a.affairtypeid AND a.isvisible='1' AND e.isvisible='1' AND o.isvisible='1' ORDER BY a.sortnum ASC,a.affairtypeid ASC,e.sortnum ASC,e.eventtypeid,o.sortnum ASC,o.actionid ASC,o.actionid ASC";
        return $this->operationRepository->runQrySql($sql);
    }

    //*******************外部调用方法****************************************************
    public function getCore($id, $keyName = 'actionid',$columns = ['*']){
        return $this->operationRepository->get($id,$keyName,$columns);
    }

}
